﻿namespace JobTools.Helper
{
    public delegate void DelegateVoidMethod();
    public delegate void DelegateVoidMethodWithParam(object obj);

    public static class RichTextBox_ext
    {
        public static void SetText_CrossThread(this RichTextBox rtb, string text)
        {
            rtb.Invoke(new DelegateVoidMethod(delegate
            {
                rtb.Text = text;
            }));
        }

        public static void AppendText_CrossThread(this RichTextBox rtb, string text, bool autoScrollToBottom = true)
        {
            rtb.Invoke(new DelegateVoidMethod(delegate
            {
                rtb.AppendText(text);
                bool autoScrollToBottom2 = autoScrollToBottom;
                if (autoScrollToBottom2)
                {
                    rtb.ScrollToBottom();
                }
            }));
        }

        public static void ScrollToBottom(this RichTextBox rtb)
        {
            rtb.Focus();
            rtb.Select(rtb.TextLength, 0);
            rtb.ScrollToCaret();
        }
    }
}
